package cn.edu360.dao.impl;

import cn.edu360.bean.ResultBean;
import cn.edu360.bean.UserBean;
import cn.edu360.dao.UserDao;
import cn.edu360.service.UserService;

public class UserServiceImpl implements UserService {
	 //登陆结果
	public ResultBean login(UserBean user) {
		ResultBean bean = new ResultBean();
		UserDao userDao = new UserDaoImpl();
		UserBean userByname = userDao.getUserByname(user.getName());
		if (userByname != null) {
			if (userByname.getPwd().equals(user.getPwd())) {
				bean.setResult(true);
				bean.setDsc("登陆成功！");
			} else {
				bean.setResult(false);
				bean.setDsc("密码不正确");
			}
		} else {
			bean.setResult(false);
			bean.setDsc("用户名不存在");
		}
		return bean;
	}
   //注册结果
	public ResultBean register(UserBean user) {
		ResultBean bean = new ResultBean();
		UserDao userDao = new UserDaoImpl();
		UserBean userByname = userDao.getUserByname(user.getName());
		if (userByname == null) {
			boolean save = userDao.save(user);
			if (save) {
				bean.setResult(true);
				bean.setDsc("注册成功");
			} else {
				bean.setResult(false);
				bean.setDsc("未知异常错误！");
			}
		} else {
			bean.setResult(false);
			bean.setDsc("不好意思，改名字已被注册........");
		}
		return bean;
	}
}
